package com.huoyun.order.action;

import java.util.Map;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.huoyun.user.bean.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class SessionCheckInterceptor implements Interceptor {

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		// 读取Session
		Map<String, Object> session = invocation.getInvocationContext().getSession();
		// 判断Session中是否有相应的attribute

		final Authentication auth = SecurityContextHolder.getContext().getAuthentication();

		final Object principal = auth.getPrincipal();

		if (principal instanceof User) {
			// user = (User) principal;
			String resultCode = invocation.invoke();
		} else {
			return "login";
		}
		return "success";

	}
}